//
//  ImageTexture.h
//  MySDLGame
//
//  Created by grg on 2020/8/2.
//  Copyright © 2020 grg. All rights reserved.
//

#ifndef ImageTexture_h
#define ImageTexture_h

#include <SDL2/SDL.h>
#include "string.h"
#include "GameWindowConfig.h"

using namespace std;

class ImageTexture {
    
public:
    ImageTexture(SDL_Renderer *render,
                 const char* imageName,
                 SDL_Rect* src =nullptr,
                 SDL_Rect*target=nullptr){
//        string path = RES_PATH + imageName;
        image = SDL_LoadBMP(imagePath(imageName));

        //////载入的图片生成SDL材质
        texture = SDL_CreateTextureFromSurface(render, image);
        int extractedExpr = SDL_RenderCopy(render,
                                           texture, nullptr, nullptr);
        SDL_RenderPresent(render);
    }
    ~ImageTexture(){
        if (image!=nullptr) {
            SDL_FreeSurface(image);
        }
        if (texture!=nullptr) {
            SDL_DestroyTexture(texture);
        }
    }
private:

    SDL_Surface* image = nullptr;
    SDL_Texture* texture = nullptr;
    
};




#endif /* ImageTexture_h */
